module.exports = function(app,entitys,loginRouter,db){
  //用户详情
  app.get('/user',loginRouter, async (req, res) => {
    res.send(await entitys.user.getById(req.query.id))
  })
  //用户列表分页查询
  app.get('/user/list',loginRouter, async (req, res) => {
    let key = req.query.key || '' //按昵称、姓名关键字查询
    res.send(await entitys.user.selectPage(
      `select * from user where nickName like "%${key}%" and name like "%${key}%"`,
      req.query.pageNum,
      req.query.pageSize
    ))
  })
  //用户新增
  app.post('/user',loginRouter, async (req, res) => {
    res.send(await entitys.user.insert(req.body))
  })
  //用户修改
  app.put('/user',loginRouter, async (req, res) => {
    res.send(await entitys.user.updateById(req.body))
  })
  //用户删除
  app.delete('/user',loginRouter, async (req, res) => {
    res.send(await entitys.user.deleteById(req.query.id))
  })
  //用户修改密码
  app.put('/user/changePassWord',loginRouter, async (req, res) => {
    res.send(await entitys.user.changePassWord(req.body.id,req.body.newPassWord))
  })
}